#include <iostream>

static char a[] = "11";
static char b[] = "101";

char* bstradd(const char a[], const char b[]) {
    size_t len = strlen(a) > strlen(b) ? strlen(a) : strlen(b);

    len++; //msb carry
    char *c = new char[len+1];
    c[len] = '\0';
    int bita, bitb, bitc;
    int carry = 0;
    
    for(int i=strlen(a)-1, j=strlen(b)-1, k=len-1; i>=0 || j>=0 ; i--, j--, k--) {
        //std::cout << i << " " << j << " " << k << std::endl;
        bita = i>=0 ? a[i] == '1' : 0;
        bitb = j>=0 ? b[j] == '1' : 0;
        bitc = (carry+bita+bitb) & 0x1;
        carry = (carry+bita+bitb) > 1 ? 1 : 0;
        c[k] = bitc==1 ? '1' : '0';
    }
    c[0] = carry ? '1' : '0';

    return c;    
}

int main(int argc, const char *argv[]) {

    char* c = bstradd(a, b);
    printf("%s + %s = %s\n", a, b, c);
    delete [] c;
    return 0;
}
